fix: only remount /sys/fs/cgroup when rooted at a nested path#173
Merged
geokat merged 2 commits intoJul 21, 2026
Merged
Conversation
The cgroup-v2 nesting setup in wrap_dockerd.sh unconditionally unmounted and remounted /sys/fs/cgroup after unsharing the cgroup namespace to ensure inner container cgroups land under the envbox container's cgroup on the host (see #169). On some runtimes, /sys/fs/cgroup is already rooted at "/" once the cgroup namespace is unshared, and remounting a live cgroupfs there can fail with EBUSY, aborting dockerd startup. This can break envbox startup in affected environments, including the README Hacking example. Read the mount root from /proc/self/mountinfo and skip the umount/remount when it's already "/", only remounting when the mount still points at a nested path from the inherited environment. Update the inline script copy and assertions in the docker tests to match. Refs: https://linear.app/codercom/issue/PLAT-383
geokat
marked this pull request as ready for review
July 20, 2026 06:49
johnstcn
reviewed
Jul 20, 2026
johnstcn
reviewed
Jul 21, 2026
Comment on lines
+194
to
+210
| # Some runtimes already root /sys/fs/cgroup at "/" after unsharing the | ||
| # cgroup namespace; remounting it again fails with EBUSY. Only remount | ||
| # when it's still rooted at a nested host path. | ||
| # When mounts are stacked at /sys/fs/cgroup, the visible mount is the | ||
| # one whose ID is not another same-location mount's parent (see | ||
| # proc_pid_mountinfo(5)). | ||
| cgroup_mount_root=$(awk ' | ||
| $5 == "/sys/fs/cgroup" { root[$1] = $4; isparent[$2] = 1 } | ||
| END { for (id in root) if (!(id in isparent)) print root[id] } | ||
| ' /proc/self/mountinfo) | ||
| if [ "$cgroup_mount_root" != "/" ]; then | ||
| # Remount /sys/fs/cgroup so the new cgroup namespace's view becomes the | ||
| # fs root; inner container cgroups end up under the envbox container's | ||
| # cgroup on the host. | ||
| umount /sys/fs/cgroup || { echo "envbox: failed to umount /sys/fs/cgroup" >&2; exit 1; } | ||
| mount -t cgroup2 cgroup /sys/fs/cgroup || { echo "envbox: failed to mount cgroup2 on /sys/fs/cgroup" >&2; exit 1; } | ||
| fi |
Member
There was a problem hiding this comment.
nit, non-blocking: We now have this logic duplicated verbatim. Might be worth de-duping? Not a blocker though and more of a follow-up.
Contributor
Author
There was a problem hiding this comment.
Good point! More than that, we're effectively triplicating this logic between this
test, TestWrapDockerdCmd, and the production script itself. It would be nice to
replace most of that with a black-box test of the wrapper's behavior, but that
would need a bit of dedicated harness/setup (good for a follow-up PR).
johnstcn
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cgroup-v2 nesting setup in wrap_dockerd.sh unconditionally unmounted and remounted /sys/fs/cgroup after unsharing the cgroup namespace to ensure inner container cgroups land under the envbox container's cgroup on the host (see #169).
On some runtimes, /sys/fs/cgroup is already rooted at "/" once the cgroup namespace is unshared, and remounting a live cgroupfs there can fail with EBUSY, aborting dockerd startup. This can break envbox startup in affected environments, including the README Hacking example.
Read the mount root from /proc/self/mountinfo and skip the umount/remount when it's already "/", only remounting when the mount still points at a nested path from the inherited environment. Update the inline script copy and assertions in the docker tests to match.
Refs: https://linear.app/codercom/issue/PLAT-383